AI Lessons
Lesson 28: Temperature and hallucinations

Purpose: To understand how the temperature setting affects an LLM's output, and why AI models confidently state things that are not true.

No. of Classes

1 - (Time : 1 hour 30 minutes, Laptops/desktops : 10, Students strength : 15 to 20).

Materials Required

Laptop / Desktop with Internet connections / Wi-Fi.

Prior knowledge
  • Basic understanding of LLMs
  • Loading and prompting LLMs using WebLLM Module
Exercises

Exercise (1)



  • Send the same prompt at temperature 0, 0.7 and 1.5, run each several times, and compare how varied the answers become.

Exercise (2)



  • Ask the LLM factual questions with verifiable answers, including a deliberately made-up one and check the responses against a reliable source. Record where the model made something up.

Solutions



Teacher's Instruction:
  1. Help students link back to Lesson 1 - the model predicts the next likely token, so a confident wrong answer is not lying, it is prediction. Discuss when it is and is not safe to trust an LLM.
  2. Explain that temperature controls randomness in next-token selection: low values (e.g., 0) pick the most probable token every time, while high values (e.g., 1.5) pick less probable tokens, increasing creativity or randomness.